/**
* <p> title �� CollegeServiceImpl.java</p>
* <p> package �� cn.edu.hit.education.service</p>
* <p> description ��TODO</p>
* <p> copyright �� ��������ҵ��ѧ(C) 2019</p>
* <p> company �� ��������ҵ��ѧAS&MT</p>
* <p> author �� ��ѩ�� jinxuesong@163.com</p>
* <p> date �� 2021��4��21�� ����4:36:36</p>
* <p> version �� v1.0 </p>
*
* Modification  History:
* Date         Author        Version        Discription
* -----------------------------------------------------------------------------------
* 2021��4��21��       ��ѩ��          1.0             1.0
* Why & What is modified: <�޸�ԭ������>
*/
package cn.edu.hit.education.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.hit.education.dao.CollegeMapper;
import cn.edu.hit.education.pojo.College;
import cn.edu.hit.education.pojo.CollegeExample;
import cn.edu.hit.education.pojo.Specialty;

@Service
public class CollegeServiceImpl implements ICollegeService {

	@Autowired
	CollegeMapper collegeMapper;
	@Autowired
	ISpecialtyService specialtyService;

	@Override
	public int insert(College college) {
		return collegeMapper.insert(college);
	}


	@Override
	public int deleteByPrimaryKey(int id) {
		return collegeMapper.deleteByPrimaryKey(id);
	}


	@Override
	public int update(College college) {
		return collegeMapper.updateByPrimaryKey(college);
	}

	@Override
	public List<College> queryAllCollege() {
		CollegeExample example = new CollegeExample();
		CollegeExample.Criteria criteria = example.createCriteria();
		criteria.andIdGreaterThan(0);
		
		return collegeMapper.selectByExample(example);
	}

	@Override
	public List<College> queryCollegesByUniversityId(int universityId) {
		CollegeExample example = new CollegeExample();
		CollegeExample.Criteria criteria = example.createCriteria();
		criteria.andUniversityIdEqualTo(universityId);
		
		return collegeMapper.selectByExample(example);
	}

	@Override
	public College queryCollegeByPrimaryKey(int id) {
		// TODO Auto-generated method stub
		return collegeMapper.selectByPrimaryKey(id);
	}


	@Override
	public int deleteByPrimaryKeyCascade(int id) {
		// TODO Auto-generated method stub
		List<Specialty> specialties = specialtyService.querySpecialtiesByCollegeId(id);
		if(specialties != null && specialties.size() > 0){
			for (Specialty specialty : specialties) {
				specialtyService.deleteByPrimaryKey(specialty.getId());
			}
		}
		
		
		return collegeMapper.deleteByPrimaryKey(id);
	}

}
